home *** CD-ROM | disk | FTP | other *** search
- Path: ix.netcom.com!netnews
- From: miker3@ix.netcom.com (Mike Rubenstein)
- Newsgroups: comp.lang.c,comp.lang.c++
- Subject: Re: Incrementing enumerated types
- Date: Wed, 31 Jan 1996 13:28:47 GMT
- Organization: Netcom
- Message-ID: <310f6d26.50322368@nntp.ix.netcom.com>
- References: <Andy.Law-3101961138310001@pc0734.ri.bbsrc.ac.uk>
- NNTP-Posting-Host: ix-dc6-05.ix.netcom.com
- X-NETCOM-Date: Wed Jan 31 5:29:09 AM PST 1996
- X-Newsreader: Forte Agent .99c/16.141
-
- Andy.Law@bbsrc.ac.uk (Andy Law) wrote:
-
- > Is it legal to increment an enumerated type? I have an enumerated list of
- > possible document types that I want to step through, and my compiler is
- > barfing on it. It seems such a waste of an enumeration if I have to resort
- > to ints to get this done.
- >
- > Alternatively does anyone have a suggestion as to how to do this kind of
- > thing legally?
- >
- > for (EnumeratedType eIndex = enum_first; eIndex < enum_last; eIndex++) {
- > ^^^^^^^^
- > /* do something */
- > }
-
- You've posted to both comp.lang.c and comp.lang.c++.
-
- Answer from comp.lang.c:
-
- Incrementing an enum is legal. Your compiler should have
- given a diagnostic for your syntax in the for statement. A
- for statement may not include a declaration in any of the
- expressions.
-
- Answer from comp.lang.c++:
-
- It is illegal to increment an enum unless you have overloaded
- operator++ for the enum (overloading for enum types a new
- feature and is not supported by many compilers yet). You can
- get the effect you want with a cast:
-
- for (EnumeratedType eIndex = enum_first;
- eIndex < enum_last;
- eIndex = EnumeratedType(eIndex + 1))
-
-
- Michael M Rubenstein
-